package router

import (
	"github.com/gin-gonic/gin"
	"github.com/samber/do/v2"

	"gitee.com/monkeyPP/happy-mall/services/userservice/internal/interfaces/api/handler"
	"gitee.com/monkeyPP/happy-mall/services/userservice/internal/interfaces/api/middleware"
)

func RegisterRoutes(router *gin.Engine, i do.Injector) {
	userHandler := do.MustInvoke[handler.UserHandler](i)
	authHandler := do.MustInvoke[handler.AuthHandler](i)

	v1 := router.Group("/api/v1")
	user := v1.Group("/user")
	{
		user.POST("/register", userHandler.Register)
		user.POST("/login", userHandler.Login)
		token := user.Group("/token")
		{
			token.POST("/refresh", authHandler.Refresh)
		}
	}

	// 下面的接口要加上 middleware
	user.Use(middleware.Auth())
	{
		user.GET("/profile", userHandler.Profile)
		user.POST("/logout", userHandler.Logout)
	}

}
